<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>多文件上传</title>

<link type="text/css" rel="stylesheet" href="<%=request.getContextPath() %>/lib/uploadify/uploadify.css"></link>
<script type="text/javascript" src="<%=request.getContextPath() %>/lib/uploadify/jquery.uploadify.min.js"></script>:


<script type="text/javascript">

/**
 * 当点击文件队列中文件的关闭按钮或点击取消上传时触发，file参数为被取消上传的文件对象
 */
var uploadify_onCancel = function(file){
	drgUI.error('文件【'+ file.name + '】取消上传');
}

/**
 * 选择文件后向队列中添加每个上传任务时如果失败都会触发
 */
var uploadify_onSelectError = function(file, errorCode, errorMsg) {  
    var msgText = "上传失败\n";  
    switch (errorCode) {  
        case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:  
            //this.queueData.errorMsg = "每次最多上传 " + this.settings.queueSizeLimit + "个文件";  
            msgText += "每次最多上传 " + this.settings.queueSizeLimit + "个文件";  
            break;  
        case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:  
            msgText += "文件大小超过限制( " + this.settings.fileSizeLimit + " )";  
            break;  
        case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:  
            msgText += "文件大小为0";  
            break;  
        case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:  
            msgText += "文件格式不正确，仅限 " + this.settings.fileTypeExts;  
            break;  
        default:  
            msgText += "错误代码：" + errorCode + "\n" + errorMsg;  
    }  
    drgUI.error(msgText);
}; 

/**
 * 文件上传出错时触发，参数由服务端程序返回。
 */
var uploadify_onUploadError = function(file, errorCode, errorMsg, errorString) {  
    // 手工取消不弹出提示  
    if (errorCode == SWFUpload.UPLOAD_ERROR.FILE_CANCELLED  
            || errorCode == SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED) {  
        return;  
    }  
    var msgText = "上传失败\n";  
    switch (errorCode) {  
        case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:  
            msgText += "HTTP 错误\n" + errorMsg;  
            break;  
        case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:  
            msgText += "上传文件丢失，请重新上传";  
            break;  
        case SWFUpload.UPLOAD_ERROR.IO_ERROR:  
            msgText += "IO错误";  
            break;  
        case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:  
            msgText += "安全性错误\n" + errorMsg;  
            break;  
        case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:  
            msgText += "每次最多上传 " + this.settings.uploadLimit + "个";  
            break;  
        case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:  
            msgText += errorMsg;  
            break;  
        case SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND:  
            msgText += "找不到指定文件，请重新操作";  
            break;  
        case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:  
            msgText += "参数错误";  
            break;  
        default:  
            msgText += "文件:" + file.name + "\n错误码:" + errorCode + "\n"  
                    + errorMsg + "\n" + errorString;  
    }  
    drgUI.error(msgText);
} 

/**
 * 当文件上传成功时触发
 */
var uploadify_onUploadSuccess = function(file, data, response) {  
	 drgUI.success(file.name + ' 上传成功！ ');
};

	$(function() {
		//添加界面的附件管理
        $('#file_upload').uploadify({
            'swf'      : '<%=request.getContextPath() %>/lib/uploadify/uploadify.swf',
            'uploader' : '<%=request.getContextPath() %>/fileUpload/filesUpload.dhc',
            'height': 30,
            'whith' :120,
            'auto'  : false,//是否自动开始
            'uploadLimit' : 100, //一次同步上传的文件数目     
            'fileSizeLimit' : '20MB', //单个文件大小，0为无限制，可接受KB,MB,GB等单位的字符串值     
            'queueSizeLimit' : 100, //队列中同时存在的文件个数限制
            'fileObjName':'file',
            'removeCompleted': true,  //是否完成后移除序列，默认为true
            'removeTimeout' : '5',  //上传完成后队列多长时间后消失。默认 3秒    需要：removeCompleted : true,时使用
            'progressData' :'percentage',//设置上传进度显示方式，percentage显示上传百分比，speed显示上传速度
            'buttonText' : '选择文件...',
            'fileTypeDesc' : '支持格式:xls/xlsx', //可选文件的描述。这个值出现在文件浏览窗口中的文件类型下拉选项中。（chrome下不支持，会显示为'自定义文件',ie and firefox下可显示描述）
            'fileTypeExts' : ' *.xls; *.xlsx',//允许上传的文件格式
            'multi'    : true,//是否支持多文件上传
            'method'   :'post',//提交方式
            'debug':false,
            'overrideEvents' : [ 'onDialogClose','onCancel', 'onUploadSuccess', 'onUploadError', 'onSelectError' ],//重写Uploadify事件
            //当点击文件队列中文件的关闭按钮或点击取消上传时触发
            'onCancel': uploadify_onCancel,
          	//返回一个错误，选择文件的时候触发  
            'onSelectError': uploadify_onSelectError, 
          	//检测FLASH失败调用  
            'onFallback':function(){  
                drgUI.success('您未安装FLASH控件，无法上传图片！请安装FLASH控件后再试! ');
            }, 
            'onUploadSuccess' : uploadify_onUploadSuccess,
            'onUploadError' : uploadify_onUploadError,
            'onQueueComplete':function(queueData){
                drgUI.success('成功上传的文件数: ' + queueData.uploadsSuccessful + ' \n 上传出错的文件数: ' + queueData.uploadsErrored);
            },

        });
    });
	
	
</script>
</head>
<body>

	<div id="filesUp">
		<h1>uploadify+springMVC包装类上传多个文件</h1>

		<input id="file_upload" type="file" name="file" /> <a
			href="javascript:$('#file_upload').uploadify('upload', '*')">上传文件</a>
		| <a href="javascript:$('#file_upload').uploadify('stop')">停止上传!</a>
		| <a href="javascript:$('#file_upload').uploadify('cancel', '*')">取消上传!</a>

	</div>
</body>
</html>